#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# Author: Jeokayne Ataier

import socket
import os


client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

client.connect(("127.0.0.1",8881))

#1.先传输文件大小信息

file_path = input("输入需要上传的文件路径：")

file_size = os.stat(file_path).st_size

client.sendall(str(file_size).encode("utf-8"))
file_read = open(file_path,"rb")
#2.开始传输文件
read_size = 0
while True:
    data = file_read.read(1024)
    client.sendall(data)
    read_size += len(data)
    #判断是否传输完成
    if read_size == file_size:
        break

client.close()
